﻿namespace PowerSong.SongDatabase.ObjectModel
    {
    using System;
    using System.IO;
    using System.Collections.Generic;

    /// <summary>
    /// Provides simple logging functionality for a PowerSong database.
    /// </summary>
    public class ActivityLog : ObjectModelBase
        {

        internal ActivityLog(Database database) : base(database) { }

        public void Write(ActivityItemType type, Guid id, ActivityAction action)
            {
            Write(type, id, action, DateTime.Now);
            }

        /// <summary>
        /// Adds the specified log entry to the activity log.
        /// </summary>
        /// <param name="itemSort">The type of log entry to record.</param>
        /// <param name="id">The ID of the item in question.</param>
        /// <param name="time">The time of the action.</param>
        /// <param name="action">The action performed.</param>
        public void Write(ActivityItemType type, Guid id, ActivityAction action, DateTime time)
            {
            Database.WriteActivity(type, id, action, time);
            }

        public LogEntry[] GetAllActivity()
            {
            return Database.Activity.ToArray();
            }

        public LogEntry[] Get(DateTime startDate, DateTime endDate)
            {

            var result = new List<LogEntry>();
            foreach (var activityEntry in Database.Activity)
                {
                if (activityEntry.Time >= startDate && activityEntry.Time < endDate) result.Add(activityEntry);
                }
            return result.ToArray();

            }

        }

    }
